﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PJ.Presentation.SalePurchase.Sale
{
    /// <summary>
    /// Logique d'interaction pour CustomerShoppingCartGrid.xaml
    /// </summary>
    public partial class CustomerShoppingCartGrid : UserControl, ICustomerShoppingCartItemListView
    {
        public IViewModel ViewModel
        {
            get
            {
                return (IViewModel)this.DataContext;
            }
            set 
            {
                if (this.DataContext != value)
                {
                    this.DataContext = value;
                    ViewModel.View = this;
                }                
            }
        }

        public CustomerShoppingCartGrid()
        {
            InitializeComponent();
            if (this.DataContext is ICustomerShoppingCartItemListModel)
                ViewModel.View = this;
        }

        private void DataGrid_InitializingNewItem(object sender, Microsoft.Windows.Controls.InitializingNewItemEventArgs e)
        {
            ((ICustomerShoppingCartItemListModel)DataContext).InitializingNewItem((ICustomerShoppingCartItemModel)e.NewItem);
        }

        private void UserControl_LostFocus(object sender, RoutedEventArgs e)
        {
            ((ICustomerShoppingCartItemListModel)DataContext).Persist();
            System.Media.SystemSounds.Beep.Play();
        }
    }
}
